<template>
  <div class="detail-container">
    <!-- 顶部公司信息卡片 -->
    <el-card class="team-card">
      <div class="team-header">
        <div class="team-left">
          <el-image :src="team.team_img" class="team-logo" fit="cover"/>
        </div>
        <div class="team-right">
          <div class="title-wrap">
            <h1 class="company-name">{{ team.team_name }}</h1>

          </div>

          <div class="contact-info">
            <div class="info-row">
              <el-icon><Phone /></el-icon>
              <span>电话：{{ team.tel }}</span>
            </div>
            <div class="info-row">
              <el-icon><Calendar /></el-icon>
              <span>成立时间：{{ dayjs(team.create_time).format('YYYY-MM-DD') }}</span>
            </div>
            <div class="info-row">
              <el-icon><Calendar /></el-icon>
              <span>简介：{{team.content}}</span>
            </div>
            <el-button
                type="primary"
                class="book-btn"
                @click="showBookingDialog = true"
            >
              立即预约
            </el-button>
          </div>
        </div>
      </div>
    </el-card>

    <!-- 主要内容区 -->
    <el-card class="content-card">
      <el-tabs>
        <el-tab-pane label="服务介绍">
          <!-- 团队成员 -->
          <div class="section">
            <div class="section-title">
              <el-icon><User /></el-icon>
              <span>团队成员</span>
            </div>
            <el-row :gutter="12" class="member-list">
              <el-col :span="3" v-for="member in teamEmp" :key="member.id">
                <el-card class="member-card" shadow="hover" :body-style="{ padding: '0' }">
                  <el-image :src="member.team_emp_avatar" class="member-avatar" fit="cover"/>
                  <div class="member-info">
                    <div class="member-name">{{ member.username }}</div>
                    <div class="member-age">{{ member.age }}岁</div>
                  </div>
                </el-card>
              </el-col>
            </el-row>
          </div>

          <div class="section">
            <div class="section-title">
              <el-icon><Message /></el-icon>
              <span>详细信息</span>
            </div>
            <div class="info-content" v-html="team.info"></div>
          </div>


        </el-tab-pane>

        <el-tab-pane label="用户评价">
          <Comment />
        </el-tab-pane>
      </el-tabs>
    </el-card>


    <!-- 预约弹窗 -->
    <el-dialog
        v-model="showBookingDialog"
        title="在线预约"
        width="600px"
        destroy-on-close
    >
      <BookingForm
          @submit="handleBookingSubmit"
      />
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import {Calendar, Location, Message, Phone, User, Van} from '@element-plus/icons-vue'
import Comment from "@/components/Comment.vue"
import { get } from "@/net/index.js"
import { useRoute } from "vue-router"
import dayjs from "dayjs"
import BookingForm from "@/components/BookingForm.vue";

const route = useRoute()
const team = ref({})
const teamEmp = ref([])
const showBookingDialog = ref(false)

const handleBookingSubmit = (formData) => {
  console.log('预约表单提交:', formData)
  ElMessage.success('预约成功！')
  showBookingDialog.value = false
}

onMounted(async () => {
  const id = route.params.id
  get(`/api/team/getTeamById/${id}`, (res) => {
    team.value = res
  })

  get(`/api/teamEmp/getTeamEmpById/${id}`, (res) => {
    teamEmp.value = res
  })
})
</script>

<style scoped>
.detail-container {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 20px;
  position: relative;
}

.team-card {
  margin-bottom: 20px;
}

.team-header {
  display: flex;
  gap: 30px;
}

.team-logo {
  width: 310px;
  height: 230px;
  border-radius: 8px;
}

.company-name {
  font-size: 28px;
  font-weight: 600;
  margin: 0;  /* 移除底部间距 */
  color: #303133;
}

.contact-info {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #606266;
}

.content-card {
  min-height: 500px;
}

.section {
  margin-bottom: 40px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.member-list {
  margin: 20px 0;
}

.member-card {
  width: 120px;
  transition: all 0.3s ease;

}

.member-card:hover {
  transform: translateY(-5px);
}

.member-avatar {
  width: 120px;  /* 减小图片宽度 */
  height: 120px;
  display: block;
}

.member-info {
  padding: 10px;
  text-align: center;
  background: #f5f7fa;
}

.member-name {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 4px;
  color: #303133;
}

.member-age {
  font-size: 13px;
  color: #909399;
}

:deep(.el-tabs__nav-wrap::after) {
  height: 1px;
}

:deep(.el-tabs__item) {
  font-size: 16px;
}

.info-content {
  line-height: 1.8;
  color: #606266;
  font-size: 14px;
  padding: 10px 0;
}

.info-content :deep(p) {
  margin-bottom: 10px;
}

.info-content :deep(img) {
  max-width: 100%;
  height: auto;
  margin: 10px 0;
}


.header-top .el-button {
  padding: 12px 30px;
  font-size: 16px;
  border-radius: 24px;
  background: #409EFF;
  box-shadow: 0 2px 12px rgba(64, 158, 255, 0.3);
  transition: all 0.3s ease;
}

.header-top .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(64, 158, 255, 0.4);
}

.title-wrap {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.company-name {
  font-size: 28px;
  font-weight: 600;
  margin: 0;
  color: #303133;
}

.book-btn {
  margin-top: 15px;
  width: 150px;
  padding: 20px 20px;
  font-size: 14px;
  border-radius: 20px;
  background: #409EFF;
}
</style>